<?php
/**
 * Svick a Fast Simple Smart PHP FrameWork
 * Author: Tommy 863758705@qq.com
 * Link: http://svick.tomener.com/
 * Since: 2022
 */

namespace Svick\Route;

/**
 * @method static Router get($uri, $callback)
 * @method static Router post($uri, $callback)
 * @method static Router put($uri, $callback)
 * @method static Router patch($uri, $callback)
 * @method static Router options($uri, $callback)
 * @method static Router delete($uri, $callback)
 * @method static Router any($uri, $callback)
 * @method static Router match(array $methods, $uri, $callback)
 */
class Route
{
    /**
     * @var Router
     */
    protected static $router;

    public static function __callStatic($name, $arguments)
    {
        if (self::$router === null) {
            self::$router = new Router();
        }

        if ($name != 'match') {
            self::$router->add([$name], ...$arguments);
        } else {
            self::$router->add(...$arguments);
        }
    }

    /**
     * 添加路由分组
     *
     * @param $name
     * @param callable $callback
     * @return void
     */
    public static function group($name, callable $callback)
    {
        self::router()->addGroup($name, $callback);
    }

    public static function router()
    {
        if (self::$router === null) {
            self::$router = new Router();
        }

        return self::$router;
    }
}
